//
//  DepartPersonListView.m
//  MobileOffice
//
//  Created by jjkj on 16/11/4.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "DepartPersonListView.h"
#import "CenterLabelTableViewCell.h"

@implementation DepartPersonListView


- (instancetype)initWithFrame:(CGRect)frame titleArr:(NSMutableArray *)titleArr{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor clearColor];
        _dataArr=titleArr;
        
        CGFloat viewHeight=titleArr.count*50;
        if (viewHeight<250) {
            viewHeight=250;
        }else if (viewHeight>IPHONE_HEIGHT-100){
            viewHeight=IPHONE_HEIGHT-100;
        }
        
        UIView *backView=[[UIView alloc]initWithFrame:frame];
        backView.backgroundColor=[UIColor blackColor];
        backView.alpha=0.4;
        [self addSubview:backView];
        
        //点击手势
        UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
        tapGesture.delegate=self;
        [tapGesture setNumberOfTapsRequired:1];
        [tapGesture setNumberOfTouchesRequired:1];
        [backView addGestureRecognizer:tapGesture];
        
        //创建列表
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(50, (IPHONE_HEIGHT-viewHeight)/2, IPHONE_WIDTH-50*2, viewHeight) style:UITableViewStylePlain];
        _tableView.layer.masksToBounds=YES;
        _tableView.layer.cornerRadius=5;
        //_myTableView.backgroundColor=[UIColor redColor];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.tag=110;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator=NO;
        _tableView.showsHorizontalScrollIndicator=NO;
        _tableView.bounces=NO;
        //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
        //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
        [self addSubview:_tableView];
        
//        CATransition *animation = [CATransition animation];
//        
//        animation.duration = 0.2f;
//        
//        animation.timingFunction = UIViewAnimationCurveEaseInOut;
//        
//        animation.fillMode = kCAFillModeForwards;
//        
//        //各种动画效果
//        
//        /*
//         
//         KCATransitionFade;
//         
//         KCATransitionMoveIn;
//         
//         KCATransitionPush;
//         
//         KCATransitionReveal;
//         
//         */
//        
//        /*
//         
//         KCATransitionFromeRight;
//         
//         KCATransitionFromLeft;
//         
//         KCATransitionFormTop;
//         
//         kCATransitionFromButtons;
//         
//         */
//        
//        //各种组合
//        
//        animation.type = kCATransitionFade;
//        
//        animation.subtype = kCATransitionFromRight;
//        
//        
//        [self.layer addAnimation:animation forKey:@"animation"];

        
    }
    return self;
}

#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *cellID=@"CenterLabelTableViewCell";
    CenterLabelTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell=[[CenterLabelTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.myTitle.width=_tableView.width;
        
        UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 49, _tableView.width, 1)];
        lineLabel.backgroundColor=BACKCOLOR_GRAY;
        [cell.contentView addSubview:lineLabel];
    }
    cell.myTitle.text=_dataArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_myBlock) {
        _myBlock(_dataArr[indexPath.row]);
        [self removeFromSuperview];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}


#pragma mark -手势点击时间
-(void)TwoTapGestureRecognizer:(UIGestureRecognizer*)gr{
    [self endEditing:YES];
    [self removeFromSuperview];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
